#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Usage:
# This script is used to autogenerate constants found in the xnnpack header file
# as constants in python, which is used in xnnpack delegate. This script requires
# the path to the XNNPACK folder as an argument

# Example:
# bash gen_xnnpack_constants.sh ~/fbsource/xplat/third-party/XNNPACK/XNNPACK


# constant's file header
{
    echo "# Copyright (c) Meta Platforms, Inc. and affiliates."
    echo "# All rights reserved."
    echo "#"
    echo "# This source code is licensed under the BSD-style license found in the"
    echo "# LICENSE file in the root directory of this source tree."
    echo ""
    echo "# Auto-generated by gen_xnnpack_constants.sh script. Do not modify"
} > xnnpack_constants.py

echo UINT32_MAX = 4294967295 >> xnnpack_constants.py
echo UINT64_MAX = 18446744073709551615 >> xnnpack_constants.py
awk '/^#define\s+XNN_/ { print $2,"=",$3} ' "$1"/include/xnnpack.h >> xnnpack_constants.py
if ! grep -qc "^XNN_" xnnpack_constants.py; then false; fi
